Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 6, 2025

Problem

The CLI was not working on Node 18, showing absolutely no output even with debug mode enabled. This was caused by the build configuration targeting ES2022, which includes JavaScript features not fully supported in Node 18 (e.g., Object.hasOwn, certain array methods). Additionally, the tsup/esbuild bundler was not explicitly configured to target Node 18.

Solution

This PR makes three minimal changes to ensure Node 18 compatibility:

  1. Updated TypeScript target from ES2022 to ES2021 in both @hey-api/openapi-ts and @hey-api/codegen-core packages. ES2021 is fully supported by Node 18 and provides all necessary modern JavaScript features.

  2. Added explicit target: 'node18' to tsup configurations to ensure esbuild compiles the code specifically for Node 18 compatibility.

  3. Improved error reporting in the CLI bin script by logging errors instead of silently exiting, which will help with debugging similar issues in the future.

  4. Added comprehensive tests in packages/openapi-ts/src/config/__tests__/engine.test.ts that verify the Node 18 compatibility configuration is maintained. These tests ensure that the TypeScript target is ES2021 and the tsup target is 'node18' in both packages, and will fail if these settings are removed.

Changes

  • packages/openapi-ts/tsconfig.base.json: ES2022 → ES2021
  • packages/codegen-core/tsconfig.base.json: ES2022 → ES2021
  • packages/openapi-ts/tsup.config.ts: Added target: 'node18'
  • packages/codegen-core/tsup.config.ts: Added target: 'node18'
  • packages/openapi-ts/bin/index.cjs: Added error logging to catch block
  • packages/openapi-ts/src/config/__tests__/engine.test.ts: Added tests to verify Node 18 compatibility configuration

Testing

  • ✅ All bin tests pass (14/14)
  • ✅ All package tests pass (908/908 for openapi-ts, including new configuration tests)
  • ✅ CLI verified working with --version, --help, and actual spec generation
  • ✅ Typecheck passes for all packages
  • ✅ Configuration tests verified to fail when Node 18 compatibility settings are removed
  • ✅ Maintains compatibility with Node 20 and 22 (as specified in engines)

Fixes the issue where users on Node 18 would get no output when running the CLI, as reported in the issue description.

Fixes #2730

Original prompt

This section details on the original issue you should resolve

<issue_title>cli does not work on node 18</issue_title>
<issue_description>### Description

When trying to generate a client using node 18 the cli seems to no be executed. Absolutely no output is shown even with debug enabled. Running it with node 20 works correctly.

Reproducible example or configuration

mise exec node@18 -- npx @hey-api/openapi-ts --input https://petstore3.swagger.io/api/v3/openapi.json --output src/client-test -d

OpenAPI specification (optional)

No response

System information (optional)

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

@mrlubos @lcdss Is this a regression? @mrlubos @lcdss Oof. Out of curiosity, why did you choose Hey API for your legacy project?
Fixes #2730

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

changeset-bot bot commented Oct 6, 2025

⚠️ No Changeset found

Latest commit: 567ebea

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Oct 6, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
hey-api-docs Ready Ready Preview Comment Oct 6, 2025 5:38pm

@Copilot Copilot AI changed the title [WIP] cli does not work on node 18 fix: add Node 18 compatibility by targeting ES2021 and node18 Oct 6, 2025
Copilot finished work on behalf of mrlubos October 6, 2025 17:19
@Copilot Copilot AI requested a review from mrlubos October 6, 2025 17:19
@mrlubos
Copy link
Member

mrlubos commented Oct 6, 2025

@copilot can you add a test that would verify this is the correct fix? It should fail if we remove the changes you've made, and it should pass if we put them back

Copy link
Contributor Author

Copilot AI commented Oct 6, 2025

@copilot can you add a test that would verify this is the correct fix? It should fail if we remove the changes you've made, and it should pass if we put them back

Added comprehensive tests in packages/openapi-ts/src/config/__tests__/engine.test.ts that verify:

  1. TypeScript target is set to ES2021 (not ES2022) in both @hey-api/openapi-ts and @hey-api/codegen-core
  2. tsup target is set to 'node18' in both packages

The tests correctly fail when these settings are removed and pass when they're in place. Verified by temporarily reverting the changes and confirming test failures.

Commit: 85dfa4b

Copy link

codecov bot commented Oct 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 29.27%. Comparing base (ee1f929) to head (567ebea).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2731      +/-   ##
==========================================
- Coverage   29.31%   29.27%   -0.04%     
==========================================
  Files         388      388              
  Lines       37803    37781      -22     
  Branches     2260     2254       -6     
==========================================
- Hits        11082    11062      -20     
+ Misses      26691    26689       -2     
  Partials       30       30              
Flag Coverage Δ
unittests 29.27% <ø> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

pkg-pr-new bot commented Oct 6, 2025

Open in StackBlitz

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/codegen-core@2731
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/nuxt@2731
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/openapi-ts@2731
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@2731

commit: 567ebea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cli does not work on node 18
2 participants